package logic

import (
	"book-hub/bookrpc/bookrpc"
	"book-hub/bookrpc/internal/svc"
	"book-hub/models"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewNovelAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelAddLogic {
	return &NovelAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *NovelAddLogic) NovelAdd(in *bookrpc.NovelAddRequest) (*bookrpc.NovelAddResponse, error) {
	// todo: add your logic here and delete this line
	var novel models.Novel
	novel = models.Novel{
		Title:        in.Title,
		Class:        in.Class,
		Label:        in.Label,
		Introduction: in.Introduction,
		UserId:       int(in.UserId),
	}
	models.DB.Create(&novel)
	return &bookrpc.NovelAddResponse{
		NovelId: int64(novel.ID),
	}, nil
}
